<template> 
	<view> 
		<view class="goods-tips" v-for="(itemList, index) in tips" :key="index">
			<text :class="'item' + index" v-for="(item, name) in itemList" :key="name">{{item}}</text>
		</view>
	</view>
</template>

<script>
	import common from '../../../../utils/common.js'
	export default {
		data () {
			return {
				tips: []
			}
		},
		props: {
			goods: {
				type: Object,
				default: {}
			}
		},
		watch: {
			goods: {
				deep: true,
				immediate: true, 
				handler: function () {
					this.update()
				}
			}
		},
		mounted () { },
		methods: {
			update () {
				var tips1 = {}
				var tips2 = {}
				// 新品上架
				// if (this.goods.is_new == 1 || !this.goods.product_sale || this.goods.product_sale == 0) {
				// 	tips1.isNew = common.changeTxt('新品上架')
				// } else {
				// 	// 已售几份
				// 	// tips1.saleCount = common.changeTxt('已售X1', {X1: this.goods.product_sale, unit1: this.goods.unit})
				// 	tips1.saleCount = common.changeTxt('已售X1', {X1: this.goods.product_sale})
				// }
				
				tips1.saleCount = common.changeTxt('已售X1', {X1: this.goods.product_sale})
		
				// 赞X1
				// if (this.goods.product_reply > 0) {
				// 	tips1.reply = common.changeTxt('赞X1', {X1: this.goods.product_reply})
				// }
				// 剩余X1
				var remainNum = 0
				if (this.goods.is_seckill_price && this.goods.seckill_stock > 0 && this.goods.seckill_stock < 10) {
					remainNum = this.goods.seckill_stock
				} else if (!this.goods.is_seckill_price && this.goods.stock > 0 && this.goods.stock < 10) {
					remainNum = this.goods.stock
				}
				if (remainNum > 0) {
					// tips1.remainNum = common.changeTxt('剩余X1', {X1: remainNum, unit1: this.goods.unit})
					tips1.remainNum = common.changeTxt('剩余X1', {X1: remainNum })
				}
				if ((this.goods.is_seckill_price && this.goods.seckill_stock == 0) || (!this.goods.is_seckill_price && this.goods.stock == 0)) {
					if (this.key) {
						tips1.stockOver = common.changeTxt('已售罄')
					}
				}
				
				// 限时优惠 限购几份  限几份优惠 （同时设置了起购和限购，则限购失效，0为不限制）
				if ((this.goods.key || !this.goods.has_spec ) && this.goods.max_num > 0 && this.goods.min_num <= 0) {
					if (!this.goods.is_seckill_price) {
						if (this.goods.limit_type == 1) {
							tips2.specialNum = common.changeTxt('每个ID限购X1', {X1: this.goods.max_num, unit1: this.goods.unit})
						} else {
							tips2.specialNum = common.changeTxt('每单限购X1', {X1: this.goods.max_num, unit1: this.goods.unit})
						}
					} else {
						if (this.goods.limit_type == 1) {
							tips2.specialNum = common.changeTxt('每个ID限X1优惠', {X1: this.goods.max_num, unit1: this.goods.unit})
						} else {
							tips2.specialNum = common.changeTxt('每单限X1优惠', {X1: this.goods.max_num, unit1: this.goods.unit})
						}
					}
				} else if (this.goods.is_seckill_price) {
					tips2.specialNum = common.changeTxt('限时优惠')
				}
				// X1折 && this.goods.seckill_stock != 0
				if (this.goods.seckill_discount && this.goods.seckill_discount > 0 && this.goods.seckill_discount < 10) {
					tips2.discountNum = common.changeTxt('X1折', {X1: this.goods.seckill_discount})
				}
				
				// 几份起购
				if (this.goods.min_num > 1) {
					tips2.minNum = common.changeTxt('X1起购', {X1: this.goods.min_num, unit1: this.goods.unit})
				}
				this.tips = []
				
				if(Object.keys(tips1).length > 0){
					this.tips.push(tips1)
				}
				
				// if(Object.keys(tips2).length > 0){
				// 	this.tips.push(tips2)
				// }
			}
		}
	
	}
</script>

<style scoped>
	.goods-tips{
		line-height: 18px;
		height: 18px;
	}
	.goods-tips .item0{
		font-size: 11px;
		color: #999;
		margin-right: 5px;
	}
	.goods-tips .item1{
		font-size: 11px;
		color: #e23321;
		margin-right: 5px;
	}
</style>
